<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Provide Degree - Choose Location Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/expand.css">
	</head>
	<body>
		<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<div class="message"></div>	
		<%	
			try {
			
			/** Get applicant object **/
				
			Applicant a = (Applicant)session.getAttribute("applicant");				
				
			/*** Determin the applicant is a non US citizen ***/
		
			if(!a.getCountryOfCitizenship().equals("United States"))
			{
				if(request.getParameter("usResidence").equals("true"))
				{
					a.setUsResidence(true);
				}
				else if(request.getParameter("usResidence").equals("false"))
				{
					a.setUsResidence(false);
				}
				else
				{
					response.sendRedirect("../residency.jsp");
				}
			}
		
			/*** Determin the status of the student (domestic or non domestic) ***/
		
			if(a.getUsResidence() == true || a.getCountryOfCitizenship().equals("United States"))
			{
				a.setDomestic(true);
			}
			else
			{
				a.setDomestic(false);
			}
		
			session.setAttribute("applicant", a);
			
			%>
			
			<h2>Previous Data:</h2>
		
		<ol class="tree">
			<li><label for="general">General Information</label><input type="checkbox" id="general" />
				<ol> 
					<li>	
						<table>	
							<tr><td>First Name:</td><td><%= a.getFirstName() %></td></tr>
							<tr><td>Middle Initial:</td><td><%= a.getMiddleInitial() %></td></tr>
							<tr><td>Last Name:</td><td><%= a.getName() %></td></tr>
							<tr><td>Country of Citizenship:</td><td><%= a.getCountryOfCitizenship() %></td></tr>
							<tr><td>Country of Residence:</td><td><%= a.getCountryOfResidence() %></td></tr>
							<tr><td>Street:</td><td><%= a.getStreet() %></td></tr>
							<tr><td>City:</td><td><%= a.getCity() %></td></tr>
							<tr><td>ZIP/Postal Code:</td><td><%= a.getZip() %></td></tr>
						<%	
							/*** Determin whether 'state' or 'country phone code' needs to be displayed ***/
						
							if(a.getCountryOfResidence().equals("United States"))
							{
								out.print("<tr><td>State:</td><td>" + a.getState() + "</td></tr>");
							}	
							else
							{
								out.print("<tr><td>Country Phone Code:</td><td>" + a.getCountryPhoneCode() + "</td></tr>");
							}
						%>
							<tr><td>Area code:</td><td><%= a.getAreaCode() %></td></tr>
							<tr><td>Number:</td><td><%= a.getNumber() %></td></tr>
						</table>
					</li>
				</ol>
			</li>
		</ol>
			
			
			<%
			
			/** Get list of degrees **/
			
			ArrayList<Degree> dAl = new ArrayList<Degree>();
			dAl = (ArrayList<Degree>)session.getAttribute("degrees");
			
					
		/*** Iterate over amount of degrees and display them ***/	
				
			for(int i = 0; i < dAl.size(); i++)
			{
			
		%>
			<ol class="tree">
				<li><label for="degree<%= i+1 %>">Degree <%= i+1 %></label><input type="checkbox" id="degree<%= i+1 %>" />
					<ol> 
						<li>	
							<table>
								<tr><td>State/Country:</td><td> <%= dAl.get(i).getLocation() %></td></tr>
								<tr><td>University:</td><td> <%= dAl.get(i).getUniversity() %></td></tr>
								<tr><td>Discipline:</td><td> <%= dAl.get(i).getDiscipline() %></td></tr>
								<tr><td>Degree Award:</td><td> <%= dAl.get(i).getMonth() %>/<%= dAl.get(i).getYear() %></td></tr>
								<tr><td>GPA:</td><td> <%= dAl.get(i).getGpa() %></td></tr>
								<tr><td>Title:</td><td> <%= dAl.get(i).getTitle() %></td></tr>
								<tr><td>Transcript:</td><td> <%= dAl.get(i).getTranscription() %></td></tr>
							</table>
						</li>
					</ol>
				</li>
			</ol>
		<% 
			} 
		
			out.print("<hr><br>");
		
			/** Get universities **/
			
			University u = new University();
			ArrayList<Location> lAl = u.getLocations();
			
			/*** Prepare auxiliary iterator 'col' to get a three-column format ***/
			
			int col = lAl.size()/3;
			
			out.print("Please select the state or country of your university<br><br>");
			out.print("<table><tr><td>");
		
			/*** Iteration for column one ***/
			
	    	for(int i=0; i<col; i++)
	    	{	
	    		/*** Select a specific state or country which has universities listed ***/
	    		
	      		out.println("<a href=\"chooseUniversity.jsp?locationOfUniversity=" + 
	      					lAl.get(i).getName() + "&locationId=" + lAl.get(i).getId() + "\">" + 
	      					lAl.get(i).getName() + "</a><br>");    
		
			}
	    
		    out.print("</td><td>");
	    
		    /*** Iteration for column two ***/
		    
	    	for(int i=col; i<(col+col); i++)
	    	{
	    		/*** Select a specific state or country which has universities listed ***/
	    		
	      		out.println("<a href=\"chooseUniversity.jsp?locationOfUniversity=" + 
      						lAl.get(i).getName() + "&locationId=" + lAl.get(i).getId() + "\">" + 
      						lAl.get(i).getName() + "</a><br>");  
			
			}
		    
	    	out.print("</td><td>");
		    
	    	/*** Iteration for column three ***/
	    	
	    	for(int i=(col+col); i<lAl.size(); i++)
	    	{
	    		/*** Select a specific state or country which has universities listed ***/
	    		
	      		out.println("<a href=\"chooseUniversity.jsp?locationOfUniversity=" + 
  							lAl.get(i).getName() + "&locationId=" + lAl.get(i).getId() + "\">" + 
  							lAl.get(i).getName() + "</a><br>"); 
			
			}
		    
	    	out.print("</td></tr></table>");
	    	
			}
			catch(Exception e)
			{
				response.sendRedirect(BASE + "error.jsp");
			}
	   	%>
	   	</div>
   	</body>
</html>